/*
 * Copyright 2015-2021 the original author or authors. Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License. You may obtain a copy of the License at
 * http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
 * either express or implied. See the License for the specific language governing permissions and limitations under the
 * License.
 */

package com.example.springbootcache.mapper;

import com.example.springbootcache.po.City;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

/**
 * @author Eddú Meléndez
 */
@Mapper
public interface CityMapper {

    @Insert("insert into city (name, country) values (#{city.name}, #{city.country})")
    void insert(@Param("city") City city);

    @Select("select id, name, country from city where country = #{country}")
    City findByName(@Param("country") String country);

    @Update("update city set name = #{city.name} where country = #{city.country}")
    int updateCache(@Param("city") City city);

    @Delete("delete city where country = #{country}")
    int delete(@Param("country") String country);
}
